#include <stdio.h>
#include <stdlib.h> //exit 函数头文件
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
  //execlp 函数
  pid_t id = fork();
  if(id == 0)
  {
    printf("you can see me\n");

    execlp("ls", "-a", "-l", NULL); //程序替换

    printf("you can see me again?");
    exit(-1);
  }

  int status = 0;
  waitpid(id, &status, 0);  //等待阻塞
  if(WEXITSTATUS(status) != 255)
    printf("子进程替换成功 exit_code:%d\n", WEXITSTATUS(status));
  else
    printf("子进程替换失败 exit_code:%d\n", WEXITSTATUS(status));

  return 0;
}

